<%--
  Created by InteldivJ IDEA.
  User: sicidivn
  Date: 2017/8/18
  Time: 10:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../commons-easyui.jsp"%>
<html>
<head>
    <title>公司管理页面</title>
    <style type="text/css">
        #companyForm > div {
            margin:10px;
            height:25px;
        }
    </style>


    <script type="text/javascript" src="<%=basePath%>common/script/customize/customize-old.js"></script>
    <script type="text/javascript" src="<%=basePath%>common/script/customize/object/object.js"></script>
    <script type="text/javascript">
        /*------------全局变量-----------*/
        var objectInfo = {};
        var typeCode ='<%=request.getParameter("typeCode")%>';
        var companyTypeMapped={
            'mainCompany':1
            ,'ourCompany':0
            ,'upCompany':2
            ,'downCompany':3
        }

        /*------js加载时候执行------*/
        //重写datebox的formatter方法
        $.fn.datebox.defaults.formatter = function(date){
            var y = date.getFullYear();
            var m = date.getMonth()+1;
            var d = date.getDate();
            return y+'-'+m+'-'+d;
        }

        /*------页面加载完成时执行------*/
        $(document).ready(function(){
            initButon();

        });

        function initButon(){
            $('#saveOrUpdateBtn').linkbutton({
                iconCls: 'icon-save'
                ,onClick:saveOrUpdateCompany
            });
        }

        function saveOrUpdateCompany(){
            var  url = basePath+'companyAction/saveOrUpdateCompany.json'
            if(currentUser.account == 'admin'){
                url+='?admin=true'
            }
            var param = getJSONFormData('companyForm');
            tmsAjax({
                url:url
                ,data:JSON.stringify(param)
                ,type:'post'
                ,contentType:'application/json'
                ,dataType:'json'
                ,success:function(data){
                    alert(data);
                },
                error:function(){
                    alert('error');
                }
            });
        }


        function linkFunction(node){
            if(node.info.type == 1 || node.info.type == 3){
                return;
            }
            objectInfo = node.info;
            $('#companyForm').css("display","block");
            tmsAjax({
                url:basePath+'companyAction/getCompanyById.json?companyid='+node.id
                ,type:'post'
                ,dataType:'json'
                ,success:function(data){
                    $('#message').text("成功找到该公司！");
                    fillingForm(data);
                }
                ,error:function(){
                    $('#message').text("没有找到该公司！");
                    fillingFormByObject(objectInfo);
                }
            });
        }


        function fillingForm(company){
            $('#companyId').val(company.companyId);
            $('#companyCode').val(company.companyCode);
            $('#companyName').val(company.companyName);
            $('#address').val(company.address);
            $('#region').val(company.region);
            $('#regAdd').val(company.regAdd);
            $('#regDate').val(company.regDate);
            $('#regMoney').val(company.regMoney);
            $('#orgType').val(company.orgType);
            $('#legalRep').val(company.legalRep);
            $('#tel').val(company.tel);
            $('#email').val(company.email);
            $('#url').val(company.url);
            $('#longitude').val(company.longitude);
            $('#latitude').val(company.latitude);
            $('#companyType').val(company.companyType);
            $('#staffMax').val(company.staffMax);
            $('#remark').val(company.remark);
            $('#pCompanyId').val(company.pCompanyId);

        }
        function fillingFormByObject(object){
            $('#companyId').val(object.objectId);
            $('#companyCode').val(object.objectCode);
            $('#companyName').val(object.objectName);
            $('#pCompanyId').val(object.companyId);
            $('#companyType').val(companyTypeMapped[typeCode]);
        }

    </script>
</head>
<body>
    <div id = "companyInfo" class="easyui-panel" data-options="fit:true,border:false" style="padding: 20px;">
        <div>
            <span id="message"></span>
        </div>
        <form id = "companyForm" style="display:none;">
            <a id="saveOrUpdateBtn">保存或更新公司信息</a>
            <input id="companyId" name="companyId" type="hidden" />
            <input id="pCompanyId" name="pCompanyId" type="hidden"/>
            <input id="companyType" name="companyType" type="hidden"/>
            <div>
                <label>公司编码</label>
                <input id="companyCode" name="companyCode" class = "easyui-validatebox textbox" data-options="readonly:true"/>
            </div>
            <div>
                <label>公司名称</label>
                <input id="companyName" name="companyName" class = "easyui-validatebox textbox" data-options="readonly:true"/>
            </div>
            <div>
                <label>公司地址</label>
                <input id="address" name="address" class = "easyui-validatebox textbox"/>
            </div>
            <div>
                <label>所在区域</label>
                <input id="region" name="region" class = "easyui-validatebox textbox"/>
            </div>
            <div>
                <label>注册地址</label>
                <input id="regAdd" name = "regAdd" class = "easyui-validatebox textbox"/>
            </div>
            <div>
                <label>注册时间</label>
                <input id="regDate" name="regDate" class = "easyui-datetimebox"/>
            </div>
            <div>
                <label>注册资金</label>
                <input id="regMoney" name="regMoney" class = "easyui-validatebox textbox"/>
            </div>
            <div>
                <label>组织形式</label>
                <input id="orgType" name="orgType" class = "easyui-validatebox textbox"/>
            </div>
            <div>
                <label>法人代表</label>
                <input id="legalRep" name="legalRep" class = "easyui-validatebox textbox"/>
            </div>
            <div>
                <label>联系方式</label>
                <input id="tel" name="tel" class = "easyui-validatebox textbox"/>
            </div>
            <div>
                <label>联系邮箱</label>
                <input id="email" name="email" class = "easyui-validatebox textbox"/>
            </div>
            <div>
                <label>公司主页</label>
                <input id="url" name="url" class = "easyui-validatebox textbox"/>
            </div>
            <div>
                <label>企业地址经度</label>
                <input id="longitude" name="longitude" class = "easyui-validatebox textbox"/>
            </div>
            <div>
                <label>企业地址纬度</label>
                <input id="latitude" name="latitude" class = "easyui-validatebox textbox"/>
            </div>
            <div>
                <label>备注</label>
                <input id="remark" name="remark" class = "easyui-validatebox textbox"/>
            </div>
        </form>
    </div>
</body>
</html>
